home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / General / ViewIt™ 2.24 Shareware / FaceWare / FaceWare.rsrc / TEXT_1279_U6. String Utilities.txt < prev    next >
Text File  |  1994-04-10  |  7KB  |  92 lines

  1. U6. String Utility Commands
  2.   ViewIt supports several commands that perform common string-related operations:  setting substrings, trimming strings, setting parameter text, converting strings from one format to another, finding strings within text blocks, and interconverting strings and numbers.
  3.  
  4. Name  Number  Parameters & Variables used
  5. SetSub  451  a,b,c,d,uString,uName
  6.   Moves the contents of uString into uName beginning at character a of uName and ending at character b (i.e. sets a substring in uName).  Undefined characters are replaced with spaces so that SetSub works even if uName is less than b characters in length, or uString is smaller than the substring.  You can optionally use parameter c to pass the address of a Pascal-type source string (instead of using uString), and/or d to pass the address of a Pascal-type destination string (instead of using uName).
  7.   NOTE:  You can get substrings using the command GetStr described in the "String Lists" topic.
  8.  
  9. TrmStr  452  a,b,uString,uName
  10.   Moves or removes leading or trailing spaces within the string uString, uName, or some other string designated by a, according to the type of adjustment specified by b.
  11.   a = string to adjust
  12.     0 or 1 = uString
  13.     2 = uName
  14.     other = address of a Pascal string
  15.   b = type of adjustment to make
  16.     1 = removes (trims) trailing spaces
  17.     0 = removes both leading and trailing spaces
  18.    -1 = removes leading spaces
  19.    -2 = moves leading spaces to end of string
  20.  
  21. SetPrm  453  a,b,c,d,uString
  22.   Resets the four parameter text strings (^0, ^1, ^2, and ^3 items in dialogs and alerts) to the strings designated by a, b, c, and d where,
  23.   0 = empty string
  24.   1 to 255 = size of substring from uString
  25.   other = address of a Pascal string
  26. If using substrings from uString, these are obtained in succession, and trimmed of both leading and trailing spaces before being assigned to parameter text.  For example, the call "FaceIt(nil,SetPrm,10,20,10,30)" would set the ^0 item to the first 10 characters of uString, ^1 to the next 20 characters, ^2 to the next 10 characters, ^3 to the next 30 characters (= 70 total characters of uString used).  This approach can be mixed with that of passing Pascal string addresses.  SetPrm is primarily provided for those programmers who do not have access to the toolbox routine ParamText, but is also useful when "writing" multiple parameter text items to a single string.
  27. NOTE:  This command is largely obsolete now since the basic control driver used with ViewIt provides a more powerful "parameter text" scheme based on the use of string lists.
  28.  
  29. CnvStr  454  a,b,c,d,uString,uName
  30.   Converts the string designated by parameter c from string type a to type b.  Parameter d designates the total number of bytes occupied by the string variable (its "storage size") which is usually larger than the number of characters in the string (the "string length").
  31.   a = source type (0 = Pascal, 1 = C, 2 = FORTRAN)
  32.   b = converted type (0 = Pascal, 1 = C, 2 = FORTRAN)
  33.   c = source string (0 or 1 = uString, 2 = uName, other = string address)
  34.   d = source string storage size (0 ‚⧠d ‚⧠256 bytes)
  35.       (if d = 0, ViewIt assumes d = 256 bytes)
  36. CnvStr preserves all fRec scratch variables, so you don't need to worry about it clobbering other values in fRec.
  37.  
  38. FndTxt  455  a,b,c,d,uResult
  39.   Searches within the text block defined by a and b for the string defined by c and d.  Note that the text block must be locked in memory during the search since FndTxt can move heap memory.  uResult returns the position of the found string as a byte offset from a, or -1 if not found.
  40.   a = address of text block to search
  41.   b = size of text block to search (bytes)
  42.   c = address of search text
  43.   d = size of search text (use -d for case sensitive search)
  44.  
  45. NumToS  471  a,b,c,d,uString
  46.   Converts a number from the variable designated by b to the string designated by a, using the format indicated by c and d.  Infinities will appear as the character "‚àû".
  47.   a = destination string
  48.     0 = uString
  49.     other = address of a Pascal string
  50.   b = source of number (as a data type)
  51.     1 = uI1    5 = uR4
  52.     2 = uI2    6 = uR8
  53.     3 = uI4    7 = uR10
  54.     4 = uI8    8 or 12 = uR12  (12 = THINK C "universal")
  55.   c = format
  56.     0 = general (= fixed point unless very large or small)
  57.     1 = floating point
  58.     2 = fixed point
  59.   d = digits (use -d to also trim trailing decimal zeroes)
  60.     if c = 0 or 1, d = significant figures (-4 used if d = 0)
  61.     if c = 2, d = decimals to display
  62.  
  63. C & Pascal Programmers:  The "FaceStorXC" files declare uR8, uR10, and uR12 as arrays of 2-byte integers:
  64.  short  uR8[4];
  65.  short  uR10[5];
  66.  short  uR12[6];
  67. The "FaceStorXP" files define these variables similarly:
  68.  uR8 : array [1..4] of integer;
  69.  uR10 : array [1..5] of integer;
  70.  uR12 : array [1..6] of integer;
  71. The reason that these fRec elements are defined as integer arrays is that we needed to ensure that the size of these variables was always 8, 10, or 12 bytes, respectively, but could not use "double" or "extended" since the meaning of these depends on both the compiler in use and on compiler options (see the "Numbers" topic in the "About Compilers" program for more information about this issue).
  72.   To work with uR8, uR10, and uR12, you will either need to "fix" the "FaceStorXY" file to declare these variables using numerical types corresponding to 8, 10, and 12-byte reals, or type cast these variables to the proper types in expressions involving real numbers.  The following lines, for example, will not compile due to a type mismatch,
  73.   uR10 := myReal;
  74.   myReal := uR10;
  75. but can be quickly fixed by applying type casts,
  76.   extended(uR10) := myReal;
  77.   myReal := extended(uR10);
  78. which assumes, of course, that the compiler is interpreting "extended" as a reference to a 10-byte real, and that the program variable "myReal" can be assigned or assigned to a variable of type extended.
  79.  
  80. SToNum  481  a,b,uString,uResult,fI1Err...
  81.   Converts a string designated by a to an integer or real number in the variable designated by b.  The "‚àû" character can be used in strings to represent infinities.  Leading and trailing spaces are ignored.
  82.   a = source string
  83.     0 = uString
  84.     other = address of a Pascal string
  85.   b = destination variable (as a data type)
  86.     1 = uI1    5 = uR4
  87.     2 = uI2    6 = uR8
  88.     3 = uI4    7 = uR10
  89.     4 = uI8    8 or 12 = uR12  (12 = THINK C "universal")
  90. If no error occurs, then uResult is set equal to zero, else uResult returns -1 and the variable (uI1...uR12) is set equal to the corresponding error value in fRec (fI1Err... fR12Err).  The default error values are zero, but these can be changed at any time to other values if you prefer a special non-zero value returned when an error occurs.
  91.   Conditions causing an error include an empty string or a string that cannot be evaluated as a number (an NAN).  A number that is out of the range of values represented by the destination variable's numerical type is either set equal to the maximum or minimum integer (for integer types), or to ¬±‚àû or 0 (for real types).
  92. C and Pascal Programmers:  See note above accompanying NumToS that describes type-casting that may be needed if working with uR8, uR10, or uR12.